<template>
  <div>
    <div class="conten">
      <div class="title">
        <i class="iconfont icon-feiji1"></i> <span>地产分类</span>
      </div>
    </div>
    <div v-if="isShow" class="show">没有搜索到相关数据</div>
    <div v-else class="main">
        <div class="cell" v-for="item in categoryList" :key="item.id" @click="detal(item.id)">
          <div class="title">{{item.title}}</div>
          <img :src="item.image" alt="" />
          <div class="info">
            <p>{{item.desc}}
            </p>
          </div>
        </div>
      </div>
  </div>
</template>

<script>
import { getCategory } from '@/api/category'
export default {
  data(){
    return{
      isShow:false,
      categoryList:[]
    }
  },
 async created(){
   if(this.$route.query.title_contains){
  const {data} = await getCategory({
    title_contains:this.$route.query.title_contains
  })
  this.categoryList = data
  if(this.categoryList.length ===0){
   this.isShow = true
  }
   }else{

     const {data} = await getCategory()
  this.categoryList = data

   }
  },
  methods:{
    detal(id){
      this.$router.push({path:'/detail', query: {id}})
    }
  }
};
</script>

<style lang="less" scoped>
@import url("https://at.alicdn.com/t/font_2904905_z3gg3pnwtwo.css");
.conten {
  width: 60%;
  margin: 20px auto;
}
.conten .title {
  color: #eeaf46;
}
.show{
  height: 66vh;
  // background-color: #E111;
  text-align: center;
}
.main {
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  width: 880px;
  .cell {
    position: relative;
    width: 200px;
    height: 250px;
    margin: 10px;
    background-color: #fff;
    border-radius: 5px;
    box-shadow: #ccc 1px 1px 2px 0px;
    overflow: hidden;
    .title{
      position: absolute;
      width: 50px;
      height: 18px;
      top: 0;
      left: 50%;
      text-align: center;
      color: #fff;
      transform: translateX(-25px);
      background-color: aqua;
      border-radius: 0 0 5px 5px;
      overflow: hidden;
    }
    img{
        width: 200px;
        height: 200px;
        object-fit:cover
    }
    .info{
      padding: 5px;
      p{
        font-size: 14px;
        line-height: 1.4;
        color: rgb(39, 39, 39);
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 2;
        overflow: hidden;
      }
    }
    &:hover{
      transform: translateY(-5px);
      transition: all 1s;
      box-shadow: #ccc 2px 3px 3px 0px;
    }
  }
}
.box-card{
  height: 156px;
  padding-top: 10px;
  opacity: 1;
  background-color: #333335;
}
</style>